<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page session="true" %>

<%@ page import="java.util.*" %>
<%@ page import="ihis.model.*" %>
<%@ page import="ihis.tms.client.*" %>
<%@ page import="java.util.Vector" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="ihis.core.IHISUtil" %>

<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Project/Team/Personal Schedule Report</title>
	<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a4/jquery.mobile-1.0a4.min.css" />
	<link type="text/css" href="http://dev.jtsage.com/cdn/datebox/latest/jquery.mobile.datebox.css" rel="stylesheet" /> 
	<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> 
	<script type="text/javascript">
		$( document ).bind( "mobileinit", function(){
			$.mobile.page.prototype.options.degradeInputs.date = 'text';
		});	
	</script>
	<script type="text/javascript" src="http://code.jquery.com/mobile/1.0a4/jquery.mobile-1.0a4.min.js"></script>
	<script type="text/javascript" src="http://dev.jtsage.com/cdn/datebox/latest/jquery.mobile.datebox.js"></script>
</head>
<%
	String filterFor = request.getParameter("filterFor");
	String startDate = request.getParameter("startDate");
	String endDate = request.getParameter("endDate");
	System.out.println("SearchSchedule.PeriodType : " + request.getParameter("periodType"));
	String periodType = request.getParameter("periodType") == null ? "" + IHISConstants.TIME_UNIT_WEEKLY : request.getParameter("periodType");
	System.out.println("SearchSchedule.PeriodType after: " + periodType);
	String user = request.getParameter("user");
	String team = request.getParameter("team");
	String project = request.getParameter("project");
	String ownerType = request.getParameter("ownerType") == null ? "" + IHISConstants.OWNERTYPE_PROJECT : request.getParameter("ownerType");
%>
<body>
	<div id="scheduleSearch" data-role="page" data-theme="a">
    
    <script>
    	function search(){
    		<%
    			String url = "#";
    			if("schedule".equals(filterFor)){
    				url = "schedule.jsp";
    			} else if("performance".equals(filterFor)){
    				url = "performance.jsp";
    			} else if("predictedCurve".equals(filterFor)){
    				url = "predictedCurve.jsp";
    			} else if("risk".equals(filterFor)){
    				url = "risk.jsp";
    			}
    		%>
    		document.search_schedule.action = "<%= url %>";
    		document.search_schedule.submit();
    	}
    	
    	$(function(){
    		$("#startDate").datepicker();
    	});
    	
    	$(function(){
    		$("#endDate").bind("click", function(){
    			$("#endDate").datepicker();
    		});
    	});
    	
    	$(function(){
    		$("#cancelButton").bind("click", function(){
    			windows.history.back();
    		});
    	});
    </script>
    
    	<div data-role="header"  data-position="fixed" data-backbtn="false">
			<a href="" id="cancelButton" data-icon="back" data-rel="back" data-transition="reverse">Cancel</a>
			<h1>SEARCH</h1>
			<a href="javascript:search()" data-icon="search" data-transition="reverse">Search</a>
		</div>
    
    	<div data-role="content">
			<form action="schedule.jsp" method="post" name="search_schedule"  data-theme="e">
				<div data-role="fieldcontain">
					<!-- 시작/종료일 -->
					<label for="startDate">Start Date :</label>
					<input type="date" name="startDate" id="startDate" value="<%= IHISUtil.isEmpty(startDate) ? "" : startDate %>"/>
					<label for="endDate">End Date :</label>
					<input type="date" name="endDate" id="endDate" value="<%= IHISUtil.isEmpty(endDate) ? "" : endDate %>" />
					
					<!-- 기간 종류 -->
					<fieldset data-role="controlgroup" data-type="horizontal">
						<legend>Choose Periodic Type :</legend>
						<input class=radiobox type="radio" name="periodType" id="monthly" value="2" 
							<%= "2".equals(periodType) ? "checked='checked'" : "" %> />
						<label for="monthly">Monthly</label>
						
						<input class=radiobox type="radio" name="periodType" id="weekly" value="1" 
							<%= "1".equals(periodType) ? "checked='checked'" : "" %>/>
						<label for="weekly">Weekly</label>
					</fieldset>
					
					<!-- Report Type : person | project -->
					<fieldset data-role="controlgroup" data-type="horizontal">
						<legend>Choose Report Type :</legend>
						<input class=radiobox type="radio" name="ownerType" id="forProject"" value="<%= IHISConstants.OWNERTYPE_PROJECT %>" 
							<%= IHISConstants.OWNERTYPE_PROJECT == Integer.parseInt(ownerType) ? "checked='checked'" : "" %> />
						<label for="forProject">PJT.</label>
						
						<input class=radiobox type="radio" name="ownerType" id="forTeam"" value="<%= IHISConstants.OWNERTYPE_TEAM %>" 
							<%= IHISConstants.OWNERTYPE_TEAM == Integer.parseInt(ownerType) ? "checked='checked'" : "" %> />
						<label for="forTeam">Team</label>
						
						<input class=radiobox type="radio" name="ownerType" id="forPerson" value="<%= IHISConstants.OWNERTYPE_PERSON %>" 
							<%= IHISConstants.OWNERTYPE_PERSON == Integer.parseInt(ownerType) ? "checked='checked'" : "" %> />
						<label for="forPerson">User</label>
					</fieldset>
					
					<label for="user">Choose User :</label>
					<select id="user" name="user" data-native-menu="true">
						<option value="0">ALL</option>
					<% 
				  		IHISTMSClient tms = new IHISTMSClient();
						Vector<Member> mresult = tms.getUsers();
						if(mresult != null)
						{
							for(int i =0; i<mresult.size(); i++)
							{
					%>
						<option <%= mresult.get(i).getId().equals(user) ? "selected='selected'" : "" %> 
							value="<%=mresult.get(i).getId()%>"><%=mresult.get(i).getName() %></option>
					<%
							}
						}
					%>
					</select>
								
					<!-- 프로젝트 -->
					<label for="project">Choose Project :</label>
					<select name="project" id="project" data-native-menu="true">
						<option value="0">ALL</option>
					<% 
						Vector<Project> presult = tms.getProjects();
						if(presult != null)
						{
							for(int i =0; i<presult.size(); i++)
							{
					%>
					
						<option <%= presult.get(i).getId().equals(project) ? "selected='selected'" : "" %> 
							value="<%=presult.get(i).getId()%>"><%=presult.get(i).getName() %></option>
					<%
							}
						}
					%>
						
					</select>
	
					<!-- 팀  -->
					<label for="team">Choose Team :</label>
					<select name="team" id="team" data-native-menu="true">
						<option value="0">ALL</option>
					<% 
						Vector<Team> tresult = tms.getTeams();
						if(tresult != null)
						{
							for(int i =0; i<tresult.size(); i++)
							{
					%>
					
						<option <%= tresult.get(i).getId().equals(team) ? "selected='selected'" : "" %> 
							value="<%=tresult.get(i).getId()%>"><%=tresult.get(i).getName() %></option>
					<%
							}
						}
					%>
						
					</select>				
				</div>
			</form>
    	</div>
    </div>
</body>
</html>